<template>
  <a-modal :title="title" :width="800" :visible="visible" :confirmLoading="confirmLoading" switchFullscreen
    @ok="handleOk" @cancel="handleCancel" cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="昵称">
          <a-input placeholder="请输入昵称" v-decorator="['nickName', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="真实姓名">
          <a-input placeholder="真实姓名" v-decorator="['realName', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="用户手机号">
          <a-input placeholder="请输入用户手机号" v-decorator="['phone', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="身份证号">
          <a-input placeholder="请输入身份证号" v-decorator="['idCard', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="封车次数">
          <a-input placeholder="封车次数" v-decorator="['sealCarNum', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="行车轨迹次数">
          <a-input placeholder="行车轨迹次数" v-decorator="['drivingTrackNum', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="信用分">
          <a-input placeholder="信用分" v-decorator="['creditScore', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="银行卡卡号">
          <a-input placeholder="银行卡卡号" v-decorator="['yhkNum', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="银行卡开户行">
          <a-input placeholder="银行卡开户行" v-decorator="['yhkKhh', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="银行卡预留手机号">
          <a-input placeholder="银行卡预留手机号" v-decorator="['yhkPhone', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="银行卡预留姓名">
          <a-input placeholder="银行卡预留姓名" v-decorator="['yhkUserName', {}]" />
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="实名审核">
          <a-select ref="select" v-model="authFlag" style="width: 120px">
            <a-select-option value="0">未提交认证</a-select-option>
            <a-select-option value="1">审核通过</a-select-option>
            <a-select-option value="2">待审核</a-select-option>
            <a-select-option value="3">审核驳回</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    httpAction
  } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "YsyUsersModal",
    data() {
      return {
        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          },
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {},
        url: {
          add: "/app/ysyUsers/add",
          edit: "/app/ysyUsers/edit",
        },
        authFlag: ''
      }
    },
    created() {},
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.authFlag = record.authFlag.toString()
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'avatarUrl', 'nickName', 'openid', 'sessionKey', 'unionid',
            'superiorCode', 'invitationCode', 'phone', 'idCard', 'realName', 'frondCard', 'backCard',
            'realFlag', 'delFlag', 'isMember', 'discount', 'province', 'city', 'area', 'source', 'creditScore',
            'balance', 'sealCarNum', 'drivingTrackNum', 'yhkUserName', 'yhkPhone', 'yhkKhh', 'yhkNum'))
          //时间格式化
          this.form.setFieldsValue({
            expireTime: this.model.expireTime ? moment(this.model.expireTime) : null
          })
        });

      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.expireTime = formData.expireTime ? formData.expireTime.format('YYYY-MM-DD HH:mm:ss') : null;

            console.log(formData)
            formData.authFlag = this.authFlag
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel() {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>